﻿Imports System.Data.SqlClient
Public Class clsREGISTRO
    Private mstrID_REGISTRO As String
    Private mstrID_VEHICULO As String
    Private mdatFECHA_HORA As Date
    Private mdatFECHA As Date
    Private mdatHORA As Date
    Private mintSUBIDAS As Integer
    Private mintBAJADAS As Integer
    Private mintBLOQUEOS As Integer
    Private mstrLONGITUD As String
    Private mstrLATITUD As String
    Private mintDISTANCIA As Integer
    Private mintVELOCIDAD As Integer
    Private mintEVENTOS As Integer
    Private mintID_PUERTA As Integer
    Private mintABORDO As Integer
    Private mstrLUGAR As String
    Private mintES_TERMINAL As Integer
    Public Property ID_REGISTRO() As String
        Get
            Return mstrID_REGISTRO
        End Get
        Set(ByVal value As String)
            mstrID_REGISTRO = value
        End Set
    End Property
    Public Property ID_VEHICULO() As String
        Get
            Return mstrID_VEHICULO
        End Get
        Set(ByVal value As String)
            mstrID_VEHICULO = value
        End Set
    End Property
    Public Property FECHA_HORA() As Date
        Get
            Return mdatFECHA_HORA
        End Get
        Set(ByVal value As Date)
            mdatFECHA_HORA = value
        End Set
    End Property
    Public Property FECHA() As Date
        Get
            Return mdatFECHA
        End Get
        Set(ByVal value As Date)
            mdatFECHA = value
        End Set
    End Property
    Public Property HORA() As Date
        Get
            Return mdatHORA
        End Get
        Set(ByVal value As Date)
            mdatHORA = value
        End Set
    End Property
    Public Property SUBIDAS() As Integer
        Get
            Return mintSUBIDAS
        End Get
        Set(ByVal value As Integer)
            mintSUBIDAS = value
        End Set
    End Property
    Public Property BAJADAS() As Integer
        Get
            Return mintBAJADAS
        End Get
        Set(ByVal value As Integer)
            mintBAJADAS = value
        End Set
    End Property
    Public Property BLOQUEOS() As Integer
        Get
            Return mintBLOQUEOS
        End Get
        Set(ByVal value As Integer)
            mintBLOQUEOS = value
        End Set
    End Property
    Public Property LONGITUD() As String
        Get
            Return mstrLONGITUD
        End Get
        Set(ByVal value As String)
            mstrLONGITUD = value
        End Set
    End Property
    Public Property LATITUD() As String
        Get
            Return mstrLATITUD
        End Get
        Set(ByVal value As String)
            mstrLATITUD = value
        End Set
    End Property
    Public Property DISTANCIA() As Integer
        Get
            Return mintDISTANCIA
        End Get
        Set(ByVal value As Integer)
            mintDISTANCIA = value
        End Set
    End Property
    Public Property VELOCIDAD() As Integer
        Get
            Return mintVELOCIDAD
        End Get
        Set(ByVal value As Integer)
            mintVELOCIDAD = value
        End Set
    End Property
    Public Property EVENTOS() As Integer
        Get
            Return mintEVENTOS
        End Get
        Set(ByVal value As Integer)
            mintEVENTOS = value
        End Set
    End Property
    Public Property ID_PUERTA() As Integer
        Get
            Return mintID_PUERTA
        End Get
        Set(ByVal value As Integer)
            mintID_PUERTA = value
        End Set
    End Property
    Public Property ABORDO() As Integer
        Get
            Return mintABORDO
        End Get
        Set(ByVal value As Integer)
            mintABORDO = value
        End Set
    End Property
    Public Property LUGAR() As String
        Get
            Return mstrLUGAR
        End Get
        Set(ByVal value As String)
            mstrLUGAR = value
        End Set
    End Property
    Public Property ES_TERMINAL() As Integer
        Get
            Return mintES_TERMINAL
        End Get
        Set(ByVal value As Integer)
            mintES_TERMINAL = value
        End Set
    End Property
    Public Sub New()
        mstrID_REGISTRO = ""
        mstrID_VEHICULO = ""
        mdatFECHA_HORA = Now()
        mdatFECHA = Now()
        mdatHORA = Now()
        mintSUBIDAS = 0
        mintBAJADAS = 0
        mintBLOQUEOS = 0
        mstrLONGITUD = ""
        mstrLATITUD = ""
        mintDISTANCIA = 0
        mintVELOCIDAD = 0
        mintEVENTOS = 0
        mintID_PUERTA = 0
        mintABORDO = 0
        mstrLUGAR = ""
        mintES_TERMINAL = 0
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into REGISTRO (" & _
                            "ID_REGISTRO," & _
                            "ID_VEHICULO," & _
                            "FECHA_HORA," & _
                            "FECHA," & _
                            "HORA," & _
                            "SUBIDAS," & _
                            "BAJADAS," & _
                            "BLOQUEOS," & _
                            "LONGITUD," & _
                            "LATITUD," & _
                            "DISTANCIA," & _
                            "VELOCIDAD," & _
                            "EVENTOS," & _
                            "ID_PUERTA," & _
                            "ABORDO," & _
                            "LUGAR," & _
                            "ES_TERMINAL)" & _
                            "VALUES (" & _
                            "SUBSTRING(@ID_REGISTRO,1,100)," & _
                            "SUBSTRING(@ID_VEHICULO,1,100)," & _
                            "@FECHA_HORA," & _
                            "@FECHA," & _
                            "@HORA," & _
                            "@SUBIDAS," & _
                            "@BAJADAS," & _
                            "@BLOQUEOS," & _
                            "@LONGITUD," & _
                            "@LATITUD," & _
                            "@DISTANCIA," & _
                            "@VELOCIDAD," & _
                            "@EVENTOS," & _
                            "@ID_PUERTA," & _
                            "@ABORDO," & _
                            "SUBSTRING(@LUGAR,1,100)," & _
                            "@ES_TERMINAL)"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = OptocontrolConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("ID_REGISTRO", mstrID_REGISTRO)
        Command.Parameters.AddWithValue("ID_VEHICULO", mstrID_VEHICULO)
        Command.Parameters.AddWithValue("FECHA_HORA", mdatFECHA_HORA)
        Command.Parameters.AddWithValue("FECHA", mdatFECHA)
        Command.Parameters.AddWithValue("HORA", mdatFECHA_HORA)
        Command.Parameters.AddWithValue("SUBIDAS", mintSUBIDAS)
        Command.Parameters.AddWithValue("BAJADAS", mintBAJADAS)
        Command.Parameters.AddWithValue("BLOQUEOS", mintBLOQUEOS)
        Command.Parameters.AddWithValue("LONGITUD", mstrLONGITUD)
        Command.Parameters.AddWithValue("LATITUD", mstrLATITUD)
        Command.Parameters.AddWithValue("DISTANCIA", mintDISTANCIA)
        Command.Parameters.AddWithValue("VELOCIDAD", mintVELOCIDAD)
        Command.Parameters.AddWithValue("EVENTOS", mintEVENTOS)
        Command.Parameters.AddWithValue("ID_PUERTA", mintID_PUERTA)
        Command.Parameters.AddWithValue("ABORDO", mintABORDO)
        Command.Parameters.AddWithValue("LUGAR", mstrLUGAR)
        Command.Parameters.AddWithValue("ES_TERMINAL", mintES_TERMINAL)

        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Aviso")
        End Try

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el registro", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
End Class
